package com.neuedu.ylbx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.ylbx.pojo.PatientRegistration;
import com.neuedu.ylbx.service.PatientsService;
import com.neuedu.ylbx.utils.ResultVo;
import com.neuedu.ylbx.vo.PatientsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/hospital")
@CrossOrigin
@Api(tags = "患者管理")
public class PatientsController {
    @Autowired
    private PatientsService patientsService;

    @ApiOperation("患者入院登记")
    @PostMapping("/patients/register")
    public ResultVo register (PatientRegistration pr) throws Exception {
        patientsService.save(pr);
        return ResultVo.ok("登记成功");
    }

    @ApiOperation("获取患者列表")
    @GetMapping("/patients")
    public ResultVo<List<PatientRegistration>> getPatientsPage () throws Exception {
        return ResultVo.ok(patientsService.list());
    }

    @ApiOperation("获取患者详情")
    @GetMapping("/patients/{id}")
    public ResultVo<List<PatientRegistration>> getPatientDetails (Integer patientId) throws Exception{
            QueryWrapper<PatientRegistration> qw = new QueryWrapper<>();
            //查询患者id
            if (patientId != null) {
                qw.eq("id", patientId);
            }
            //执行查询
            List<PatientRegistration> patientList = patientsService.list(qw);

        return ResultVo.ok(patientList);
    }
}
